<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>  
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery-2.1.0.js"></script>
    <script src="js/pintuer.js"></script>  
</head>
<body>
<form >
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 约课管理</strong></div>
    <div class="padding border-bottom">
      <ul class="search">
         <li>状态
          <select   id="mystatus"   name="s_ishome" class="input"  style="width:75px; line-height:17px; display:inline-block">
            <option value="">请选择</option>
            <option value="0">未处理</option>
            <option value="1">已处理</option>
          </select>
          &nbsp;&nbsp;
                      年级
          <select   id="smygrade"  name="s_isvouch" class="input"   style="width:100px; line-height:17px;display:inline-block">
             <option value="">请选择</option>
            <option value="1">小学一年级</option>
            <option value="2">小学二年级</option>
              <option value="3">小学三年级</option>
                <option value="4">小学四年级</option>
                  <option value="5">小学五年级</option>
                    <option value="6">初中一年级</option>
                      <option value="7">初中二年级</option>
                        <option value="8">初中三年级</option>
                          <option value="9">初中四年级</option>
                            <option value="10">高中一年级</option>
                             <option value="11">高中二年级</option>
                              <option value="12">高中三年级</option>
                            
          </select>
          &nbsp;&nbsp;
                      教师查询
            <select  id="smyteacher"  name="s_isvouch" class="input" style="width:100px; line-height:17px;display:inline-block">
          
          </select>
        </li>
        <li>
          <input  id="istart" type="text" placeholder="请输入开始时间" name="keywords" class="input" style="width:130px; line-height:17px;display:inline-block" />
          <input  style="width:2px; line-height:2px;display:inline-block" />
          <input  id="iend" type="text" placeholder="请输入结束时间" name="keywords" class="input" style="width:130px; line-height:17px;display:inline-block" />
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="searchByTime()" > 时间搜索</a>
        </li>
       
      </ul>
    </div>
    <table  id="yuyuetable"  class="table table-hover text-center">
     
    </table>
    <tr>
    	<td colspan="8">
    		<div class="pagelist"> 
    			<a id='first_page'  href="#">首页</a> 
    			<a id='last_page'   href="#">上一页</a> 
    		    <a id='next_page'   href="#">下一页</a>
    		    <a id='end_page'    href="#">尾页</a>
    		    <a id='jump_page'   href="#">跳转</a>
    		    <input id="page_no" style="height: 20px;width:30px"/>
    		    <input id="total_page"style="height: 20px;width:50px"  value="1 页"/>
    		</div>
    	</td>
    </tr>
  </div>
</form>
<script type="text/javascript">


$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

function DelSelect(){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false; 		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

</script>
</body>

<script type="text/javascript">
           /*上传的数据*/
     	   var val;
     	   //所有的预约数据
     	   var datas;
		   $(window).load(function() {
			 val = {
			 	 "mode":"1",
			 	 "deal":"0"
			 };
                net();
                teacherinit();
			 });
			 
			 function net()
		 {
		 	
     var url = 'http://119.3.231.67:8080/ZDEduBooking/servlet/QueryBookingServlet';
      $.ajax({
        url: url,
      	type: 'POST',
        data: {
						DATA: JSON.stringify(val)
			  },
        dataType: 'json',
        crossDomain: true,
        success: function(data) {
        	//数组存储
        	 datas = data;
        	 //获取第一页，6条数据
        	 getPages(1,6);
          
        },
		error: function(xhr, type, errorThrown) {
			alert("服务器异常，请稍后再试:" + type);
		}
      });
      
		}
		 
		  //用于页码跳转方法
    function jumPage(totalPage,psize){
      var cpage=jQuery("#page_no").val();
      if(0< cpage && cpage <= totalPage){
        getPages(cpage,psize);
      }
      else{
        alert("Out of range");
      }
    }
		 
		 
		 function getPages(pno,psize) {
		$("#yuyuetable").empty(); 	
      var num;//分页总行数
      var totalPage = 0;//分页总页数
      var pageSize = psize;//分页每行显示数
      var currentPage = pno;//当前页
      
      $("#yuyuetable").append('<tr><th width="120">约课编号</th><th>姓名</th><th>电话</th><th>年级</th><th>科目</th><th>教师</th><th>备注</th><th width="120">预约时间</th><th>操作</th></tr>');

      num = parseInt(datas.blist.length);//获取数据行数
      if (num / pageSize > parseInt(num / pageSize)) {
        totalPage = parseInt(num / pageSize) + 1;
      } else {
        totalPage = parseInt(num / pageSize);
      }
      var startRow = (currentPage - 1) * pageSize + 1;//开始显示的行
      var endRow = currentPage * pageSize;//结束显示的行
      endRow = (endRow > num) ? num : endRow;

      
      for (var i = 0; i < datas.blist.length; i++) {
      	 if (startRow <= parseInt(i + 1) && parseInt(i + 1) <= endRow) {
			                var bid = datas.blist[i].bookingid;
							var bname= datas.blist[i].name;
							var phone= datas.blist[i].phone;
						    var btime= datas.blist[i].bookingtime;
							var teacher= datas.blist[i].teachername;
							var garde= datas.blist[i].gradename;
							var course= datas.blist[i].coursename;
							var status= datas.blist[i].bookingstatus;
							var backup=datas.blist[i].backup;
                            if(status=='0')
                            {
                            	$("#yuyuetable").append('<tr><td><input type="checkbox" name="id[]" value="1" />'+ bid+'</td><td>'+bname +'</td><td>'+phone+'</td><td>'+garde+'</td><td>'+course+'</td><td>'+teacher+'</td><td>'+backup+'</td><td>'+btime+'</td><td><div class="button-group"> <a class="button border-red" href="javascript:void(0)" onclick="popmyconfirm('+bid+')"><span class="icon-trash-o"></span> 未处理</a> </div></td></tr>');
                            }
                            else{
                            	$("#yuyuetable").append('<tr><td><input type="checkbox" name="id[]" value="1" />'+ bid+'</td><td>'+bname +'</td><td>'+phone+'</td><td>'+garde+'</td><td>'+course+'</td><td>'+teacher+'</td><td>'+backup+'</td><td>'+btime+'</td><td><div class="button-group"> <a class="button borborder-green" href="javascript:void(0)" ><span class="icon-check"></span> 已处理</a> </div></td></tr>');
                            }				
        }
      }
     
        //每次执行分页代码时需要将前一次分页的判断结果清空
        jQuery("#last_page").removeAttr("onclick");
        jQuery("#next_page").removeAttr("onclick");
        //当前页非第一页时
        if (currentPage > 1) {
          jQuery("#last_page").attr("onclick", "getPages(" + (parseInt(currentPage) - 1) + "," + psize + ")");
        }
        //当前页小于总页数时
        if (currentPage < totalPage) {
          jQuery("#next_page").attr("onclick", "getPages(" + (parseInt(currentPage) + 1) + "," + psize + ")");

        }
        //显示当前页码、总页数及生成跳转点击事件
        jQuery("#end_page").attr("onclick", "getPages(" + (totalPage) + "," + psize + ")");
        jQuery("#first_page").attr("onclick", "getPages(" + (1) + "," + psize + ")");
        jQuery("#jump_page").attr("onclick", "jumPage(" + (totalPage) + "," + psize + ")");
        jQuery("#total_page").val("共" + totalPage + " 页");
        jQuery("#page_no").val(currentPage);

    }
		 
		 
		 
		 
		 /*获取教师名列表*/
		  function teacherinit()
		  {
		  	 
		  	val = {
			 	"mode":"3"
			 };
		  	 $("#smyteacher").empty();
		  	 $("#smyteacher").append('<option value="">请选择</option>');
		  	  var url = 'http://119.3.231.67:8080/ZDEduBooking/servlet/QueryTeacherServlet';
      $.ajax({
        url: url,
      	type: 'POST',
        data: {
						DATA: JSON.stringify(val)
			  },
        dataType: 'json',
        crossDomain: true,
        success: function(data) {
        	if(data.tlist!=null)
        	{
        		  for(var i = 0; i < data.tlist.length; i++) {
							var tid = data.tlist[i].teacherid;
							var teachername= data.tlist[i].teachername;
                             $("#smyteacher").append("<option value='"+tid+"'>"+teachername+"</option>");
						}
        	}
        
        },
						error: function(xhr, type, errorThrown) {
							alert("服务器异常，请稍后再试:" + type);
						}
      });
		  	
		  }

                $("#mystatus").change(function () {  
                $("#smygrade").get(0).selectedIndex=0;
                $("#smyteacher").get(0).selectedIndex=0;
                var ss = $(this).children('option:selected').val();  
                if (ss == "0")  //未处理
                {
                  val = {
			 	    "mode":"1",
			 	    "deal":"0"
			      };
			      $("#yuyuetable").empty();
                   net();
                }
                else if (ss == "1")  //已处理
                {
                   val = {
			 	    "mode":"1",
			 	    "deal":"1"
			      };
			      $("#yuyuetable").empty();
                   net();
                }  
            });   
            
            
                 $("#smygrade").change(function() { 
                 	 $("#mystatus").get(0).selectedIndex=0;
                 	 $("#smyteacher").get(0).selectedIndex=0;
                var ss = $(this).children('option:selected').val();  
                if(ss=='')
                {
                	 val = {
			 	 "mode":"1",
			 	 "deal":"0"
			 };
                }
                else{
                	val = {
			 	    "mode":"3",
			 	    "gradeid":ss
			      };
                }
                  
			      $("#yuyuetable").empty();
                   net();
            });   
            
             $("#smyteacher").change(function() { 
                 	 $("#mystatus").get(0).selectedIndex=0;
                 	 $("#smygrade").get(0).selectedIndex=0;
                var ss = $(this).children('option:selected').val();  
                 if(ss=='')
                 {
                 	 val = {
			 	 "mode":"1",
			 	 "deal":"0"
			 };
                 }
                 else
                 {
                 	val = {
			 	    "mode":"4",
			 	    "teacherid":ss
			      };
                 }
                  
                   net();
            });   
            /*获取当前时间*/
            function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
            /*设置开始和结束时间*/
            $('#istart').val(getNowFormatDate());
            $('#iend').val(getNowFormatDate())
            
            function searchByTime(){
            	 val = {
			 	"mode":"2",
			 	"starttime": $('#istart').val(),
			 	"endtime":$('#iend').val()
			 };
                net();
            }
            
            function popmyconfirm(myval)
            {
            	var msg=confirm("确认处理完此预约吗？");
            	if(msg==true)
            	{
            		 val = {
			 	     "bookingid":myval
			         };
			         modifybooking();
			        
            	}
            }
            
             /*修改预约状态*/
		  function modifybooking()
		  {
		  	  var url = 'http://119.3.231.67:8080/ZDEduBooking/servlet/UpdateBookingServlet';
      $.ajax({
        url: url,
      	type: 'POST',
        data: {
						DATA: JSON.stringify(val)
			  },
        dataType: 'json',
        crossDomain: true,
        success: function(data) {
        	if(data.result=='0')
        	{
        		alert('修改成功');
                 window.location.reload(true)
        	}
        	else{
        		alert('修改失败');
        	}
        
        },
						error: function(xhr, type, errorThrown) {
							alert("服务器异常，请稍后再试:" + type);
						}
      });
		  	
		  }
</script>

</html>